package com.tbit.uqbike.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 交易状态枚举
 *
 *
 * @author <a href="mailto:chen.chaoxiong@tbit.com.cn">ChenChaoXiong</a>
 * @since 2024/5/27
 */
@Getter
@AllArgsConstructor
public enum TradeStatusEnum {
    SUCCESS("success", "成功"),
    FAIL("fail", "失败"),
    UNKNOWN("unknown", "未知");

    @EnumValue
    private String status;

    private String desc;

    @Override
    public String toString() {
        return status;
    }

    public static TradeStatusEnum getEnum(String status) {
        for (TradeStatusEnum tradeStatusEnum : TradeStatusEnum.values()) {
            if (tradeStatusEnum.getStatus().equals(status)) {
                return tradeStatusEnum;
            }
        }
        return null;
    }

    public static String getDescByStatus(String status) {
        for (TradeStatusEnum tradeStatusEnum : TradeStatusEnum.values()) {
            if (tradeStatusEnum.getStatus().equals(status)) {
                return tradeStatusEnum.getDesc();
            }
        }
        return null;
    }

    public static String getStatusByDesc(String desc) {
        for (TradeStatusEnum tradeStatusEnum : TradeStatusEnum.values()) {
            if (tradeStatusEnum.getDesc().equals(desc)) {
                return tradeStatusEnum.getStatus();
            }
        }
        return null;
    }

}
